feat(npu): support CANN 9.1 MegaMoe for Qwen3.5#1989
Draft
pjgao wants to merge 8 commits into
Draft
Conversation
pjgao
force-pushed
the
feat/cann91-megamoe-qwen35
branch
from
July 21, 2026 05:45
95f44e7 to
024e1de
Compare
This was referenced Jul 21, 2026
georgezhanglei85-eng
pushed a commit
to georgezhanglei85-eng/xllm
that referenced
this pull request
Jul 21, 2026
georgezhanglei85-eng
pushed a commit
to georgezhanglei85-eng/xllm
that referenced
this pull request
Jul 23, 2026
通信资源: MegaMoeCommResource + MegaMoeCommResourceSlot, ProcessGroup 持有 - 单例符号加载, span 校验, 有界缓存 - 无 LaunchFence (避免 pipeline 空泡) - hccl_comm() 返回 comm_, resolve_hccl_comm 名字反查 fallback 算子接入: npu_mega_moe.cpp + apply_npu_mega_moe() - 参照 npu_dispatch_ffn_combine.cpp 模式 - has_mega_moe() 符号检查 + TORCH_CHECK 输入验证 权重缓存: 4 成员变量 + ensure_mega_moe_weights() - transpose+contiguous+select 一次构建 - 无 padding (moe_tp_size=1, CANN 支持 intermediate=512) 路由: select_global_experts() 消除代码重复 Policy: bool enable_mega_moe + initialize_mega_moe() 构造时检查 config: kernel_config 新增 enable_mega_moe 开关
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景与目标
Qwen3.5-35B-A3B 是 MoE 模型。原有 NPU FusedMoE 路径将专家路由、跨 rank token dispatch、专家 FFN、激活和 combine 拆成多个阶段,带来额外的 kernel launch、中间张量读写以及通信与计算衔接开销。
CANN 9.1 ops-transformer 提供 MegaMoe,将 MC2 通信与专家 FFN 组合到统一算子路径。本 PR 将该算子接入 xLLM,为 A3 上的 Qwen3.5 decode 优化提供基础,同时保留不满足能力条件时的原有 FusedMoE fallback。
接入方案
1. 配置与能力判断
mega_moe_policy中集中检查平台、模型、dtype、shape、EP 拓扑和算子可用性。2. ProcessGroup 级通信资源
MegaMoeCommResource,由 NPU ProcessGroup 管理 KFC/HCCL context、远端 window 和拓扑信息。3. ACL 算子适配
aclnnMegaMoeGetWorkspaceSize与aclnnMegaMoe。4. FusedMoE 运行时接入
fused_moe根据 policy 选择 MegaMoe 或原有 fallback。mega_moe_runtime整理本地专家权重、输入、FP32 top-k 权重、通信 context 和输出张量。定位过程中遇到的问题与解决方法
intermediate_hidden=512,A2/A3 共用检查误用了 A2 的 1024 下界fence/noneA/B 证明 fence 与精度无关并删除 fenceACL_ERROR_RT_KERNEL_DUPLICATE (507028)为什么删除 launch fence
旧实现假设下一层 host launch 会改写共享 KFC context,因此在同一通信资源的连续 MegaMoe 调用间记录 event,并在下一次调用前等待。
算子侧确认 KFC context 支持跨层复用。代码检查也表明 context 仅在资源初始化时写入,forward 只读传递 context tensor。受控实验进一步验证:
fence与none的 579 smoke 全文 hash 相同;fence的 24 个并发短输出一致;none服务共 48 个并发短输出一致;因此 fence 不是精度修复。删除它同时去掉每层 event 记录、下一层 event wait 和同 communicator 的 host launch 串行化。本文不据此声明具体性能增益,性能数字仍应由独立 profiler/benchmark 给出。
代码改动规模与分布
当前 PR 相对
main修改 37 个文件,新增 3283 行、删除 15 行,净增 3268 行。依赖关系
2d281a246f438d026b277319b3126ba430f9ae8a:提供 A3 MegaMoeintermediate_hidden=512的 host tiling 支持。21cab2b6af14f18f56b7453024319065c8fb9764:修复多 worker 首次懒注册竞态。本 PR 的 gitlink 已固定到该 commit,应先合入 doc: update readme acknowledgment. #2。本接入不依赖 xllm-ops 的
DispatchFFNCombine修改。验证环境
ascend910_93,EP8 使用 8 张 NPU,每张 64 GiB HBMnpu-smi 26.0.rc120260616_1851084487a8ae13c16daf1a2179d7520e71e6b21445f3b2f73a7fe102a95a56209323d27a3e7b0b3eaaca58321cab2b6af14f18f56b7453024319065c8fb9764e5dfadffe259920b6add5035908faf851347b571a652ef7f161647cf1a6287a7验证结果
聚焦测试与构建
build-gate3正式 xLLM binary 增量构建通过;最终构建只重编 Triton adapter 的直接依赖并重链接 xLLM,未重复大范围产品构建。KernelRegistry RED→GREEN
507028,请求断连507028或rtKernelLaunch failed,真实生成和 24 请求并发验证通过EP8 服务级验证
579507028、非法内存访问或进程异常上述属于针对 MegaMoe 跨 rank 随机 token 和首次 kernel 注册竞态的服务级集成回归,不等同于完整 CEval/GSM8K 分数评测。
PR 范围
本 PR 只提交 MegaMoe 接入、EP/DP 适配、通信资源管理、ABI/shape 校验和精度相关运行时修复。机器相关权重加载适配不进入本 PR。